<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<style>
    .register{
        display: flex;
        /*text-align: center;*/
        flex-direction:column;
        align-items:center;
        margin: 133px;
    }
    .tab{
        margin: 0 0 5px;
        font-size: 15px;
        /*display: flex;*/
        /*flex-direction:row;*/
        /*justify-content: space-around;*/
    }
    .lab{
        width: 100px;
        float: left;
        margin: 5px;

    }
    .inp{
        height: 25px;
    }
</style>
<body>
<div class="register">
    <div>
        <h3>登录</h3>
    </div>
    <div class="tab">
        <label class="lab"  for="user_name">用户名:</label>
        <input class="inp name" type="text" value="" placeholder="账号">
    </div>

    <div class="tab">
        <label class="lab" for="user_name">密码:</label>
        <input  class="inp pwd" type="text" value="" placeholder="密码">
    </div>
    <div>
        <button class="login">登录</button>
    </div>
    <div>
        <a href="/toRegister">没有账号?立即注册</a>
    </div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="/dwz/layer/layui.js"></script>
<script>
    $(function (){

        layui.use('layer', function(){
            var layer = layui.layer;
            // layer.msg('Hello World');
        });
        const htp = "http://127.0.0.1"
        // const htp = "http://gotobby.cn"
        $('.login').click(function () {
            var name = $('.name').val()
            var pwd = $('.pwd').val()
            if (name == '') {
                layer.msg('账号不能为空')
                return false
            }
            if(pwd == ''){
                layer.msg('密码不能为空')
                return false
            }
            var url = htp+"/login";
            $.post(url,{
                username:name,
                password:pwd,
            },function (res){
                layer.msg(res.msg)
                if(res.code !=200){
                    return  false
                }
                sessionStorage.setItem("token", res.data.token);
                setInterval(function (){
                    window.location.href = htp+"/music/searchMuisc"
                },1000)
            })
        })
    })

</script>
</html>